package com.andryyu.learn.ui

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.andryu.base.constant.CommonConstants
import com.andryu.base.entity.LearnVideoPageEntity
import com.andryu.learn.databinding.FragmentVideoPageBinding
import com.andryyu.learn.adapter.LearnVideoAdapter
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import javax.inject.Named

@AndroidEntryPoint
class VideoPageFragment : Fragment() {

    private var _binding: FragmentVideoPageBinding? = null
    //This property is only valid between onCreateView and onDestroyView.
    private val binding get() = _binding!!
    @Inject
    @Named("VideoList")
    lateinit var mDataList: MutableList<LearnVideoPageEntity<*>>
    private lateinit var mAdapter: LearnVideoAdapter

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentVideoPageBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.rvVideo.layoutManager = LinearLayoutManager(context)
        mAdapter = LearnVideoAdapter(mDataList)
        binding.rvVideo.adapter = mAdapter
        mAdapter.setOnItemClick {
            val intent = Intent(activity, it.cls)
            intent.putExtra(CommonConstants.NAVI_INTENT_INT, it.intentId)
            startActivity(intent)
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}